package com.template.templateuser.domain.web;

import com.template.templateuser.domain.dto.SysMenuDTO;
import com.template.templateuser.domain.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys-menu")
@Api(tags = "菜单Api")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;
    
    /**
     * 得到菜单树结构
     * @param
     * @return
     */
    @GetMapping("/list/tree")
    @ApiOperation("得到菜单树结构")
    public List<SysMenuDTO> getSysMenuListTree(){
        return sysMenuService.getSysMenuListTree();
    }


    /**
     * 根据父id得到下级菜单
     * @param
     * @return
     */
    @PostMapping("/list/tree/{parentId}")
    @ApiOperation("根据父id得到下级菜单")
    public List<SysMenuDTO> getSysMenuListByParentId(@PathVariable("parentId") Long parentId){
        return sysMenuService.getSysMenuListByParentId(parentId);
    }
    
    /**
     * 保存菜单信息
     * @param sysMenuDTO
     * @returns
     */
    @PostMapping("/save")
    @ApiOperation("保存菜单信息")
    public int saveSysMenu(@RequestBody SysMenuDTO sysMenuDTO){
        return sysMenuService.saveSysMenu(sysMenuDTO);
    }

    /**
     * 更新菜单信息
     * @param sysMenuDTO
     * @param id
     * @returns
     */
    @PostMapping("/update/{id}")
    @ApiOperation("更新菜单信息")
    public int updateSysMenu(@PathVariable("id") Long  id, @RequestBody SysMenuDTO sysMenuDTO){
        return sysMenuService.updateSysMenu(id,sysMenuDTO);
    }
    /**
     * 查看菜单信息
     * @returns
     */
    @GetMapping("/query/{id}")
    @ApiOperation("查看菜单信息")
    public SysMenuDTO querySysMenu(@PathVariable("id") Long  id){
        return sysMenuService.querySysMenu(id);
    }

    /**
     * 删除菜单信息
     * @returns
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除菜单信息")
    public int deleteSysMenu(@PathVariable("id") Long  id){
        return sysMenuService.deleteSysMenu(id);
    }
}
